<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2022/7/29
 * Time: 下午2:31
 */

namespace app\common\lib\astrolog;

use app\common\lib\astrolog\SynastryReport;

/**
 * Class HowToWooHim
 * @package app\common\lib\astrolog
 */
class HowToWooHim extends LogicBase
{
    /**
     * 单例
     * @var HowToWooHim
     */
    protected static $instance;

    /**
     * 计算报告时产生的错误信息
     * @var string
     */
    protected $error = '';

    /**
     * 用户档案信息
     * @var array
     */
    protected $userRecord = [];

    /**
     * 匹配档案的星盘数据
     * @var array
     */
    protected $astroData = [];

    /**
     * 星盘配置
     * @var array
     */
    protected $setting = [
        'natal' => [
            'planet' => [
                [1, 7.5], [1, 6], [1, 3.5], [1, 4], [1, 4], [1, 4.5], [1, 4.5], [1, 2.5], [1, 2.5], [1, 2.5],
                [0, 0], [0, 0], [0, 0], [0, 0], [1, 2.5], [0, 0], [0, 0], [1, 2.5], [1, 2.5], [1, 2.5], [1, 2.5]
            ],
            'phase' => [
                0 => [1, 0], 60 => [1, 0], 90 => [1, 0], 120 => [1, 0], 180 => [1, 0],
                45 => [0, 0], 135 => [0, 0], 30 => [0, 0], 150 => [0, 0], 72 => [0, 0], 144 => [0, 0]
            ],
            'arabic' => [
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]
            ],
            'h_sys' => 'p',
            'firdaria' => 'default',
            'bound_type' => 'default',
            'ecliptic' => 0,
            'profection_push_direction' => 0,
            'decanates' => 0,
            'ayanamsa' => 0,
            'location_use' => 0
        ],
        'synastry' => [
            'asp_orb_all' => [0 => 2, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
            'asps_display' => [0, 60, 90, 120, 180],
            'planets_display' => '111111111100100001001',
            'planet_orb_all' => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            'h_sys' => 'p',
        ],
    ];

    /**
     * 获取实例
     * @return HowToWooHim
     */
    public static function getInstance(): HowToWooHim
    {
        if (!(self::$instance instanceof self))
        {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 设置档案信息
     * @param array $record 0=>左侧档案信息,1=>右侧档案信息
     * @return HowToWooHim
     */
    public function setUserRecord($record = []): HowToWooHim
    {
        $this->userRecord = $record;
        return $this;
    }

    /**
     * 计算星盘数据
     * @return $this
     */
    private function getAstroData(): self
    {
        // 初始化当前星盘数据
        $this->astroData = [];
        // 左侧档案本命星盘数据
        $natal1 = Astrolog::getInstance()
            ->setRecode1($this->userRecord[0])
            ->setExecPrefix(config('astrolog.prefix'))
            // 设置为true获取星盘结构数据与互容接纳数据
            ->setIsAstrolabe(false)
            ->setUserSetting($this->setting)
            // version>1会计算行星中点相位、光线围攻、夹宫、夹星、夹制、夹辅
            ->setVersion(1)
            ->setGetDatas(['natal'])
            ->getAstroDatas()
            ->getDatas('natal');
        // 右侧档案本命星盘数据
        $natal2 = Astrolog::getInstance()
            ->setRecode1($this->userRecord[1])
            ->setExecPrefix(config('astrolog.prefix'))
            // 设置为true获取星盘结构数据与互容接纳数据
            ->setIsAstrolabe(false)
            ->setUserSetting($this->setting)
            // version>1会计算行星中点相位、光线围攻、夹宫、夹星、夹制、夹辅
            ->setVersion(1)
            ->setGetDatas(['natal'])
            ->getAstroDatas()
            ->getDatas('natal');

        $synastry = Astrolog::getInstance()
            ->setRecode1($this->userRecord[1])
            ->setRecode2($this->userRecord[0])
            ->setExecPrefix(config('astrolog.prefix'))
            // 设置为true获取星盘结构数据与互容接纳数据
            ->setIsAstrolabe(false)
            ->setUserSetting($this->setting)
            // version>1会计算行星中点相位、光线围攻、夹宫、夹星、夹制、夹辅
            ->setVersion(1)
            ->setGetDatas(['synastry'])
            ->getAstroDatas()
            ->getDatas('synastry');

        $this->astroData['natal'][0] = json_decode(json_encode($natal1), true);
        $this->astroData['natal'][1] = json_decode(json_encode($natal2), true);
        $this->astroData['synastry'] = json_decode(json_encode($synastry), true);
        return $this;
    }

    /**
     * 获取错误信息
     * 调用方式：$errorMessage = HowToWooHim::getInstance()->getError();
     * @return string
     */
    public function getError(): string
    {
        return $this->error;
    }

    /**
     * 怎么追求Ta
     * 调用方式：HowToWooHim::getInstance()->setUserRecord($userRecord)->init();
     *  $userRecord array 两个档案，0=>左侧档案信息,1=>右侧档案信息
     *  {
     *      "code": [
     *          "10000005", // Ta可能喜欢的类型
     *          "10000100", // Ta可能喜欢的类型
     *          "1001001100", // 我有哪些优势
     *          "1001001101", // 我有哪些优势
     *          "1001010000", // 我有哪些优势
     *          "1001010001", // 我有哪些优势
     *          "1002000501", // Ta有哪些雷区和禁忌
     *          "1002010501", // Ta有哪些雷区和禁忌
     *          "1002020701", // Ta有哪些雷区和禁忌
     *          "1002030001", // Ta有哪些雷区和禁忌
     *          "10030005", // 应该怎么做 - 怎么做是Ta喜欢的方式
     *          "10030105", // 应该怎么做 - 怎么做满足Ta的安全感
     *          "10030209", // 应该怎么做 - 两个人适合的相处模式
     *          "10030309", // 应该怎么做 - 两个人适合的相处模式
     *          "10030403", // 应该怎么做 - 两个人适合的相处模式
     *          "1003059", // 应该怎么做 - 两个人适合的相处模式
     *          "10030600" // 应该怎么做 - 两个人适合的相处模式
     *      ],
     *      "difficulty": 4, // 追求难度星级
     *      "rival": 3, // 竞争对手数
     *      "best": [ // 最佳追求时间
     *          "2022-08",
     *          "2022-11",
     *          "2023-07"
     *      ]
     * }
     */
    public function init()
    {
        $flag = '0' . date('d') % 2;// 逢日期为偶数取第一条，为奇数则取第二条
        /**
         * Ta可能喜欢的类型
         */
        $res = $this->free(); // 获取免费计算的数据
        /**
         * 我有哪些优势
         */
        // 上升星座
        $ascInSign0 = $this->astroData['natal'][0]['planets'][ASC]['in_sign_id'];
        // 太阳星座
        $sunInSign0 = $this->astroData['natal'][0]['planets'][0]['in_sign_id'];
        $res['code'][] = '100100' . $this->modNumLength2($ascInSign0 - 1) . '00';
        $res['code'][] = '100100' . $this->modNumLength2($ascInSign0 - 1) . '01';
        $res['code'][] = '100101' . $this->modNumLength2($sunInSign0 - 1) . '00';
        $res['code'][] = '100101' . $this->modNumLength2($sunInSign0 - 1) . '01';
        /**
         * Ta有哪些雷区和禁忌
         */
        // Ta 月亮落座
        $moonInSign1 = $this->astroData['natal'][1]['planets'][3]['in_sign_id'];
        // Ta 金星落座
        $venuInSign1 = $this->astroData['natal'][1]['planets'][3]['in_sign_id'];
        // Ta 上升星座
        $ascInSign1 = $this->astroData['natal'][1]['planets'][ASC]['in_sign_id'];
        // Ta 太阳星座
        $sunInSign1 = $this->astroData['natal'][0]['planets'][0]['in_sign_id'];
        $res['code'][] = '100200' . $this->modNumLength2($moonInSign1 - 1) . $flag;
        $res['code'][] = '100201' . $this->modNumLength2($venuInSign1 - 1) . $flag;
        $res['code'][] = '100202' . $this->modNumLength2($ascInSign1 - 1) . $flag;
        $res['code'][] = '100203' . $this->modNumLength2($sunInSign1 - 1) . $flag;
        /**
         * 应该怎么做
         */
        //   怎么做是Ta喜欢的方式 Ta 金星落座 $venuInSign1
        $res['code'][] = '100300' . $this->modNumLength2($venuInSign1 - 1);
        //   怎么做满足Ta的安全感 Ta 月亮落座 $moonInSign1
        $res['code'][] = '100301' . $this->modNumLength2($moonInSign1 - 1);
        //   两个人适合的相处模式
        //      a的金星落b的宫位
        $aVenuInbHouse = $this->astroData['synastry'][0]['planets'][3]['in_house_id'];
        //      a的太阳落b的宫位
        $aSunInbHouse = $this->astroData['synastry'][0]['planets'][0]['in_house_id'];
        //      a的月亮落b的宫位
        $aMoonInbHouse = $this->astroData['synastry'][0]['planets'][1]['in_house_id'];
        $res['code'][] = '100302' . $this->modNumLength2($aVenuInbHouse - 1);
        $res['code'][] = '100303' . $this->modNumLength2($aSunInbHouse - 1);
        $res['code'][] = '100304' . $this->modNumLength2($aMoonInbHouse - 1);
        // 外圈星体 群星N宫
        $inHouseArr = [
            1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0,
            7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0
        ];
        for ($i = 0; $i < 7; $i++)
        {
            $inHouseArr[$this->astroData['synastry'][0]['planets'][$i]['in_house_id']]++;
        }
        foreach ($inHouseArr as $k1 => $v1)
        {
            if ($v1 >= 3)
            {
                $res['code'][] = '100305' . $this->modNumLength2($k1 - 1);
            }
        }
        // 古典七星空相
        if ($this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 0))
        {
            $res['code'][] = '10030600';
        }
        if ($this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 1))
        {
            $res['code'][] = '10030601';
        }
        if ($this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 2))
        {
            $res['code'][] = '10030602';
        }
        if ($this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 3))
        {
            $res['code'][] = '10030603';
        }
        if ($this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 4))
        {
            $res['code'][] = '10030604';
        }
        if ($this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 5)
            || $this->isPlanetEmptyPhase($this->astroData['synastry'][0]['planets'], 6))
        {
            $res['code'][] = '10030605';
        }

        //   最佳追求时间
        $res['best'] = (new SynastryReport())
            ->setRecode1($this->userRecord[0])
            ->setRecode2($this->userRecord[1])
            ->setStartTime(time())->goodForWoo();

        return $res;
    }

    /**
     * 免费解锁内容
     * Ta可能喜欢的类型
     * 调用方式：HowToWooHim::getInstance()->setUserRecord($userRecord)->free();
     * $userRecord array 两个档案，0=>左侧档案信息,1=>右侧档案信息
     *  {
     *      "code": [
     *          "10000005", // Ta可能喜欢的类型
     *          "10000100", // Ta可能喜欢的类型
     *      ],
     *      "difficulty": 4, // 追求难度星级
     *      "rival": 3, // 竞争对手数
     * }
     */
    public function free()
    {
        $res = [];
        $this->getAstroData();

        // Ta 金星落座
        $venuInSign = $this->astroData['natal'][1]['planets'][3]['in_sign_id'];
        // Ta 5宫头落座
        $house5ProtectInSign = $this->astroData['natal'][1]['houses'][5]['in_sign_id'];
        $res['code'][] = '100000' . $this->modNumLength2($venuInSign - 1);
        $res['code'][] = '100001' . $this->modNumLength2($house5ProtectInSign - 1);

        $score1 = 0;
        /**
         * 追求难度星级🌟
         * 1.上升星座
         * a.白羊座 +2
         * b.金牛座 +3
         * c.双子座 +3
         * d.巨蟹座 +1
         * e.狮子座 +2
         * f.处女座 +5
         * g.天秤座 +4
         * h.天蝎座 +4
         * i.射手座 +4
         * j.摩羯座 +5
         * k.水瓶座 +5
         * l.双鱼座 +1
         * 2.太阳星座
         * a.白羊座 +2
         * b.金牛座 +3
         * c.双子座 +3
         * d.巨蟹座 +1
         * e.狮子座 +2
         * f.处女座 +5
         * g.天秤座 +4
         * h.天蝎座 +4
         * i.射手座 +4
         * j.摩羯座 +5
         * k.水瓶座 +5
         * l.双鱼座 +1
         * 3.金星星座
         * a.白羊座 +2
         * b.金牛座 +3
         * c.双子座 +3
         * d.巨蟹座 +1
         * e.狮子座 +2
         * f.处女座 +5
         * g.天秤座 +4
         * h.天蝎座 +4
         * i.射手座 +4
         * j.摩羯座 +5
         * k.水瓶座 +5
         * l.双鱼座 +1
         * 4.月亮星座
         * a.白羊座 +2
         * b.金牛座 +3
         * c.双子座 +3
         * d.巨蟹座 +1
         * e.狮子座 +2
         * f.处女座 +5
         * g.天秤座 +4
         * h.天蝎座 +4
         * i.射手座 +4
         * j.摩羯座 +5
         * k.水瓶座 +5
         * l.双鱼座 +1
         * 5.金星相位
         * a.空相（不与日月水金火木土天海冥产生相位）+3
         * b.与木星有和谐相位（0度/60度/120度） +1
         * c.与木星有困难相位（90度/180度） +5
         * d.与土星有和谐相位（0度/60度/120度） +3
         * e.与土星有困难相位（90度/180度） +5
         * f.与月亮有和谐相位（0度/60度/120度） +1
         * g.与月亮有困难相位（90度/180度） +5
         * 分值计算说明：
         * 1-7  1颗星 轻而易举拿下Ta
         * 8-14  2颗星 你追Ta隔层纱
         * 15-21  3颗星 追求Ta需要一点勇气哦
         * 22-28  4颗星 有难度但不是没希望
         * 29-35  5颗星 搞定Ta比登天还难
         */
        switch ($this->astroData['natal'][1]['planets'][ASC]['in_sign_id'])
        {
            case 1:
                $score1 += 2;
                break;
            case 2:
                $score1 += 3;
                break;
            case 3:
                $score1 += 3;
                break;
            case 4:
                $score1 += 1;
                break;
            case 5:
                $score1 += 2;
                break;
            case 6:
                $score1 += 5;
                break;
            case 7:
                $score1 += 4;
                break;
            case 8:
                $score1 += 4;
                break;
            case 9:
                $score1 += 4;
                break;
            case 10:
                $score1 += 5;
                break;
            case 11:
                $score1 += 5;
                break;
            case 12:
                $score1 += 1;
                break;
        }
        switch ($this->astroData['natal'][1]['planets'][0]['in_sign_id'])
        {
            case 1:
                $score1 += 2;
                break;
            case 2:
                $score1 += 3;
                break;
            case 3:
                $score1 += 3;
                break;
            case 4:
                $score1 += 1;
                break;
            case 5:
                $score1 += 2;
                break;
            case 6:
                $score1 += 5;
                break;
            case 7:
                $score1 += 4;
                break;
            case 8:
                $score1 += 4;
                break;
            case 9:
                $score1 += 4;
                break;
            case 10:
                $score1 += 5;
                break;
            case 11:
                $score1 += 5;
                break;
            case 12:
                $score1 += 1;
                break;
        }
        switch ($this->astroData['natal'][1]['planets'][3]['in_sign_id'])
        {
            case 1:
                $score1 += 2;
                break;
            case 2:
                $score1 += 3;
                break;
            case 3:
                $score1 += 3;
                break;
            case 4:
                $score1 += 1;
                break;
            case 5:
                $score1 += 2;
                break;
            case 6:
                $score1 += 5;
                break;
            case 7:
                $score1 += 4;
                break;
            case 8:
                $score1 += 4;
                break;
            case 9:
                $score1 += 4;
                break;
            case 10:
                $score1 += 5;
                break;
            case 11:
                $score1 += 5;
                break;
            case 12:
                $score1 += 1;
                break;
        }
        switch ($this->astroData['natal'][1]['planets'][1]['in_sign_id'])
        {
            case 1:
                $score1 += 2;
                break;
            case 2:
                $score1 += 3;
                break;
            case 3:
                $score1 += 3;
                break;
            case 4:
                $score1 += 1;
                break;
            case 5:
                $score1 += 2;
                break;
            case 6:
                $score1 += 5;
                break;
            case 7:
                $score1 += 4;
                break;
            case 8:
                $score1 += 4;
                break;
            case 9:
                $score1 += 4;
                break;
            case 10:
                $score1 += 5;
                break;
            case 11:
                $score1 += 5;
                break;
            case 12:
                $score1 += 1;
                break;
        }
        if ($this->isPlanetEmptyPhase($this->astroData['natal'][1]['planets'], 3))
        {
            $score1 += 3;
        } else
        {
            if ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 5, [0, 60, 120]))
            {
                $score1 += 1;
            } elseif ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 5, [90, 180]))
            {
                $score1 += 5;
            }
            if ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 6, [0, 60, 120]))
            {
                $score1 += 3;
            } elseif ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 6, [90, 180]))
            {
                $score1 += 5;
            }
            if ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 1, [0, 60, 120]))
            {
                $score1 += 1;
            } elseif ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 1, 6, [90, 180]))
            {
                $score1 += 5;
            }
        }
        if ($score1 >= 29)
        {
            $res['difficulty'] = 5;
        } elseif ($score1 >= 22)
        {
            $res['difficulty'] = 4;
        } elseif ($score1 >= 15)
        {
            $res['difficulty'] = 3;
        } elseif ($score1 >= 8)
        {
            $res['difficulty'] = 2;
        } else
        {
            $res['difficulty'] = 1;
        }

        /**
         * 获取合盘分数，修改原油星级
         */
        $options = [
            'recode1' => $this->userRecord[0],
            'recode2' => $this->userRecord[1],// 刚添加的档案
            'type' => 1,// 获取简易数据，只需要分数和最佳关系
        ];
        $synastryResult = (new SynastryData())->getScore($options);
        $synastryScore = array_sum(array_column($synastryResult['score'], 'num'));
        if ($synastryScore <= 30)
        {
            $change = 8;
        } elseif ($synastryScore <= 60)
        {
            $change = 7;
        } elseif ($synastryScore <= 90)
        {
            $change = 6;
        } elseif ($synastryScore <= 120)
        {
            $change = 5;
        } elseif ($synastryScore <= 150)
        {
            $change = 4;
        } elseif ($synastryScore <= 180)
        {
            $change = 3;
        } elseif ($synastryScore <= 210)
        {
            $change = 2;
        } elseif ($synastryScore <= 240)
        {
            $change = 1;
        } elseif ($synastryScore <= 300)
        {
            $change = 0;
        } elseif ($synastryScore <= 330)
        {
            $change = -1;
        } elseif ($synastryScore <= 360)
        {
            $change = -2;
        } elseif ($synastryScore <= 390)
        {
            $change = -3;
        } elseif ($synastryScore <= 420)
        {
            $change = -4;
        } elseif ($synastryScore <= 450)
        {
            $change = -5;
        } elseif ($synastryScore <= 480)
        {
            $change = -6;
        } elseif ($synastryScore <= 510)
        {
            $change = -7;
        } elseif ($synastryScore <= 540)
        {
            $change = -8;
        } elseif ($synastryScore <= 570)
        {
            $change = -9;
        } else
        {
            $change = -10;
        }

        $res['difficulty'] -= $change * 0.5;

        if ($res['difficulty'] > 5)
        {
            $res['difficulty'] = 5;
        } elseif ($res['difficulty'] <= 0)
        {
            $res['difficulty'] = 0.5;
        }

        $score2 = 0;
        /**
         * 潜在竞争对手
         * 逻辑：
         * 1.5宫内星
         * A.空宫 +1
         * B.太阳+3
         * C.月亮+3
         * D.水星+3
         * E.金星+5
         * F.火星+1
         * G.土星+1
         * H.木星+5
         * I.天王星+3
         * J.海王星+5
         * K.冥王星+1
         * 2.7宫内星
         * A.空宫 +1
         * B.太阳+3
         * C.月亮+3
         * D.水星+3
         * E.金星+5
         * F.火星+1
         * G.土星+1
         * H.木星+5
         * I.天王星+3
         * J.海王星+5
         * K.冥王星+1
         * 3.11宫内星
         * A.空宫 +1
         * B.太阳+3
         * C.月亮+3
         * D.水星+3
         * E.金星+5
         * F.火星+1
         * G.土星+1
         * H.木星+5
         * I.天王星+3
         * J.海王星+5
         * K.冥王星+1
         * 4.5宫主和7宫主的相位（不同时为金星和木星，也不同时为金星和土星）
         * A.没有相位+1
         * B.困难相位（90度/180度）+1
         * C.和谐相位（0度/60度/120度）+3
         * 5.5宫主与命主的相位（不同时为金星和木星，也不同时为金星和土星）
         * A.没有相位+1
         * B.困难相位（90度/180度）+1
         * C.和谐相位（0度/60度/120度）+3
         * 6.7宫主与命主的相位（不同时为金星和木星，也不同时为金星和土星）
         * A.没有相位+1
         * B.困难相位（90度/180度）+1
         * C.和谐相位（0度/60度/120度）+3
         * 7.5宫主与土星的相位（当5宫主为土星 此题分值为 +1）
         * A.没有相位+5
         * B.困难相位（90度/180度）+1
         * C.和谐相位（0度/60度/120度）+3
         * 8.7宫主与土星的相位（当7宫主为土星 此题分值为 +1）
         * A.没有相位+5
         * B.困难相位（90度/180度）+1
         * C.和谐相位（0度/60度/120度）+3
         * 9.5宫主在几宫
         * A.1宫 +3
         * B.2宫+3
         * C.3宫 +3
         * D.4宫 +3
         * E.5宫 +5
         * F.6宫 +3
         * G.7宫+5
         * H.8宫+3
         * I.9宫 +3
         * J.10宫 +3
         * K.11宫 +5
         * L.12宫 +1
         * 10.7宫主在几宫
         * A.1宫 +3
         * B.2宫+3
         * C.3宫 +3
         * D.4宫 +3
         * E.5宫 +5
         * F.6宫 +3
         * G.7宫+5
         * H.8宫+3
         * I.9宫 +3
         * J.10宫 +3
         * K.11宫 +5
         * L.12宫 +1
         * 11.金星在几宫
         * A.1宫 +3
         * B.2宫+3
         * C.3宫 +3
         * D.4宫 +3
         * E.5宫 +5
         * F.6宫 +3
         * G.7宫+5
         * H.8宫+3
         * I.9宫 +3
         * J.10宫 +3
         * K.11宫 +5
         * L.12宫 +1
         * 12.金星相位
         * A.空相（不与日月水金火木土天海冥产生相位）+1
         * B.与木星有相位（0度/60度/120度/90度/180度） +5
         * C.与土星有困难相位（90度/180度） +1
         * D.除了以上选项，与其他星产生相位（包括与土星的和谐相位） +3
         * 分值计算说明：
         * 1-14分为几乎没有
         * 15-32分为有点多
         * 33分以上为去排队
         */
        if ($this->astroData['natal'][1]['houses'][5]['have_planet_num'] === 0)
        {
            $score2 += 1;
        } else
        {
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 0, 5))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 1, 5))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 2, 5))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 3, 5))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 4, 5))
            {
                $score2 += 1;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 5, 5))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 6, 5))
            {
                $score2 += 1;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 7, 5))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 8, 5))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 9, 5))
            {
                $score2 += 1;
            }
        }
        if ($this->astroData['natal'][1]['houses'][7]['have_planet_num'] === 0)
        {
            $score2 += 1;
        } else
        {
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 0, 7))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 1, 7))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 2, 7))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 3, 7))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 4, 7))
            {
                $score2 += 1;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 7, 7))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 6, 7))
            {
                $score2 += 1;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 7, 7))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 8, 7))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 9, 7))
            {
                $score2 += 1;
            }
        }
        if ($this->astroData['natal'][1]['houses'][11]['have_planet_num'] === 0)
        {
            $score2 += 1;
        } else
        {
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 0, 11))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 1, 11))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 2, 11))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 3, 11))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 4, 11))
            {
                $score2 += 1;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 11, 11))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 6, 11))
            {
                $score2 += 1;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 7, 11))
            {
                $score2 += 3;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 8, 11))
            {
                $score2 += 5;
            }
            if ($this->isPlanetInHouse($this->astroData['natal'][1]['planets'], 9, 11))
            {
                $score2 += 1;
            }
        }
        if (($this->astroData['natal'][1]['houses'][5]['protect_ancient_id'] === 3
                && !in_array($this->astroData['natal'][1]['houses'][7]['protect_ancient_id'], [5, 6], false))
            || ($this->astroData['natal'][1]['houses'][7]['protect_ancient_id'] === 3
                && !in_array($this->astroData['natal'][1]['houses'][5]['protect_ancient_id'], [5, 6], false)))
        {
            if ($this->isHouseProtectPhaseHouseProtect($this->astroData['natal'][1], 5, 7, [90, 180]))
            {
                $score2 += 1;
            } elseif ($this->isHouseProtectPhaseHouseProtect($this->astroData['natal'][1], 5, 7, [0, 60, 120]))
            {
                $score2 += 3;
            } else
            {
                $score2 += 1;
            }
        }
        if (($this->astroData['natal'][1]['houses'][5]['protect_ancient_id'] === 3
                && !in_array($this->astroData['natal'][1]['houses'][1]['protect_ancient_id'], [5, 6], false))
            || ($this->astroData['natal'][1]['houses'][1]['protect_ancient_id'] === 3
                && !in_array($this->astroData['natal'][1]['houses'][5]['protect_ancient_id'], [5, 6], false)))
        {
            if ($this->isHouseProtectPhaseHouseProtect($this->astroData['natal'][1], 5, 1, [90, 180]))
            {
                $score2 += 1;
            } elseif ($this->isHouseProtectPhaseHouseProtect($this->astroData['natal'][1], 5, 1, [0, 60, 120]))
            {
                $score2 += 3;
            } else
            {
                $score2 += 1;
            }
        }
        if (($this->astroData['natal'][1]['houses'][1]['protect_ancient_id'] === 3
                && !in_array($this->astroData['natal'][1]['houses'][7]['protect_ancient_id'], [5, 6], false))
            || ($this->astroData['natal'][1]['houses'][7]['protect_ancient_id'] === 3
                && !in_array($this->astroData['natal'][1]['houses'][1]['protect_ancient_id'], [5, 6], false)))
        {
            if ($this->isHouseProtectPhaseHouseProtect($this->astroData['natal'][1], 1, 7, [90, 180]))
            {
                $score2 += 1;
            } elseif ($this->isHouseProtectPhaseHouseProtect($this->astroData['natal'][1], 1, 7, [0, 60, 120]))
            {
                $score2 += 3;
            } else
            {
                $score2 += 1;
            }
        }
        if ($this->astroData['natal'][1]['houses'][5]['protect_ancient_id'] === 6)
        {
            $score2 += 1;
        } else
        {
            if ($this->isHouseProtectPhasePlanet($this->astroData['natal'][1], 5, 6, [90, 180]))
            {
                $score2 += 1;
            } elseif ($this->isHouseProtectPhasePlanet($this->astroData['natal'][1], 5, 6, [0, 60, 120]))
            {
                $score2 += 3;
            } else
            {
                $score2 += 5;
            }
        }
        if ($this->astroData['natal'][1]['houses'][7]['protect_ancient_id'] === 6)
        {
            $score2 += 1;
        } else
        {
            if ($this->isHouseProtectPhasePlanet($this->astroData['natal'][1], 7, 6, [90, 180]))
            {
                $score2 += 1;
            } elseif ($this->isHouseProtectPhasePlanet($this->astroData['natal'][1], 7, 6, [0, 60, 120]))
            {
                $score2 += 3;
            } else
            {
                $score2 += 5;
            }
        }
        switch ($this->astroData['natal'][1]['houses'][5]['protect_ancient_inhouse_id'])
        {
            case 1:
                $score2 += 3;
                break;
            case 2:
                $score2 += 3;
                break;
            case 3:
                $score2 += 3;
                break;
            case 4:
                $score2 += 3;
                break;
            case 5:
                $score2 += 5;
                break;
            case 6:
                $score2 += 3;
                break;
            case 7:
                $score2 += 5;
                break;
            case 8:
                $score2 += 3;
                break;
            case 9:
                $score2 += 3;
                break;
            case 10:
                $score2 += 3;
                break;
            case 11:
                $score2 += 5;
                break;
            case 12:
                $score2 += 1;
                break;
        }
        switch ($this->astroData['natal'][1]['houses'][7]['protect_ancient_inhouse_id'])
        {
            case 1:
                $score2 += 3;
                break;
            case 2:
                $score2 += 3;
                break;
            case 3:
                $score2 += 3;
                break;
            case 4:
                $score2 += 3;
                break;
            case 5:
                $score2 += 5;
                break;
            case 6:
                $score2 += 3;
                break;
            case 7:
                $score2 += 5;
                break;
            case 8:
                $score2 += 3;
                break;
            case 9:
                $score2 += 3;
                break;
            case 10:
                $score2 += 3;
                break;
            case 11:
                $score2 += 5;
                break;
            case 12:
                $score2 += 1;
                break;
        }
        switch ($this->astroData['natal'][1]['planets'][3]['in_house_id'])
        {
            case 1:
                $score2 += 3;
                break;
            case 2:
                $score2 += 3;
                break;
            case 3:
                $score2 += 3;
                break;
            case 4:
                $score2 += 3;
                break;
            case 5:
                $score2 += 5;
                break;
            case 6:
                $score2 += 3;
                break;
            case 7:
                $score2 += 5;
                break;
            case 8:
                $score2 += 3;
                break;
            case 9:
                $score2 += 3;
                break;
            case 10:
                $score2 += 3;
                break;
            case 11:
                $score2 += 5;
                break;
            case 12:
                $score2 += 1;
                break;
        }
        if ($this->isPlanetEmptyPhase($this->astroData['natal'][1]['planets'], 3))
        {
            $score2 += 1;
        } else
        {
            if ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 5, [0, 60, 90, 120, 180]))
            {
                $score2 += 5;
            }
            if ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 6, [90, 180]))
            {
                $score2 += 1;
            }
            if ($this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 0, [0, 60, 90, 120, 180])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 1, [0, 60, 90, 120, 180])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 2, [0, 60, 90, 120, 180])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 4, [0, 60, 90, 120, 180])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 6, [0, 60, 120])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 7, [0, 60, 90, 120, 180])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 8, [0, 60, 90, 120, 180])
                || $this->isPlanetPhasePlanet($this->astroData['natal'][1]['planets'], 3, 9, [0, 60, 90, 120, 180])
            )
            {
                $score2 += 3;
            }
        }
        if ($score2 >= 33)
        {
            $res['rival'] = 3;
        } elseif ($score2 >= 15)
        {
            $res['rival'] = 2;
        } else
        {
            $res['rival'] = 1;
        }

        return $res;
    }
}
